package com.it.client;

import com.it.interceptor.ClientLoginInterceptor;
import com.it.service.MessageService;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

public class CXFProxyClient {
    private static final String ADDRESS = "http://localhost:8080/services/MessageService?wsdl"; // WebService服务地址

    public static void main(String[] args) {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setAddress(ADDRESS);
        jaxWsProxyFactoryBean.setServiceClass(MessageService.class);
        jaxWsProxyFactoryBean.getOutInterceptors().add(
                new ClientLoginInterceptor("admin","123456") // 设置用户名，密码
        );
        MessageService messageService = (MessageService)jaxWsProxyFactoryBean.create();
        String echo = messageService.echo("[webservice proxy invoke]");
        System.out.println("echo = " + echo);
    }

}
